home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / gtlayout-source.lha / LTP_DefaultEditRoutine.c < prev    next >
C/C++ Source or Header  |  1995-03-25  |  3KB  |  156 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. ULONG __asm __saveds
  10. LTP_DefaultEditRoutine(register __a0 struct Hook *Hook,register __a2 struct SGWork *Work,register __a1 ULONG *Msg)
  11. {
  12.     if(*Msg == SGH_KEY)
  13.     {
  14.         if(Work -> IEvent -> ie_Code == 0x5F)
  15.         {
  16.             LayoutHandle *Handle = Hook -> h_Data;
  17.  
  18.             if(Handle -> HelpHook)
  19.             {
  20.                 Work -> Code    = 0x5F;
  21.                 Work -> Actions    = (Work -> Actions & ~SGA_BEEP) | SGA_END | SGA_USE;
  22.  
  23.                 LTP_AddHistory(Work);
  24.  
  25.                 return(TRUE);
  26.             }
  27.         }
  28.  
  29.         if(Work -> IEvent -> ie_Code == CURSORUP || Work -> IEvent -> ie_Code == CURSORDOWN)
  30.             LTP_HandleHistory(Work);
  31.  
  32.         if(Work -> EditOp == EO_ENTER)
  33.         {
  34.             LayoutHandle    *Handle = Hook -> h_Data;
  35.             ObjectNode    *Node;
  36.             BOOLEAN      Activate = TRUE;
  37.  
  38.             if(GETOBJECT(Work -> Gadget,Node))
  39.             {
  40.                 if(Node -> Type == STRING_KIND)
  41.                 {
  42.                     if(Node -> Special . String . LastGadget)
  43.                         Activate = FALSE;
  44.                 }
  45. #ifndef DO_HEXHOOK
  46.                 else
  47.                 {
  48.                     if(Node -> Type == INTEGER_KIND)
  49.                     {
  50.                         if(Node -> Special . Integer . LastGadget)
  51.                             Activate = FALSE;
  52.                     }
  53.                 }
  54. #endif
  55.             }
  56.  
  57.             if(!(Work -> IEvent -> ie_Qualifier & QUALIFIER_SHIFT))
  58.             {
  59.                 if(Activate && Handle -> AutoActivate)
  60.                     Work -> Actions |= SGA_NEXTACTIVE;
  61.  
  62.                 if(!(Work -> Actions & SGA_NEXTACTIVE))
  63.                     Work -> Code = '\r';
  64.             }
  65.         }
  66.  
  67.         if(Work -> IEvent -> ie_Code == CURSORRIGHT && (Work -> IEvent -> ie_Qualifier & QUALIFIER_CONTROL))
  68.         {
  69.             if(Work -> BufferPos != Work -> NumChars)
  70.             {
  71.                 WORD i,Position = -1;
  72.  
  73.                 for(i = Work -> BufferPos ; i < Work -> NumChars ; i++)
  74.                 {
  75.                     if(Work -> WorkBuffer[i] == ' ')
  76.                     {
  77.                         for( ; i < Work -> NumChars ; i++)
  78.                         {
  79.                             if(Work -> WorkBuffer[i] != ' ')
  80.                             {
  81.                                 Position = i;
  82.  
  83.                                 break;
  84.                             }
  85.                         }
  86.  
  87.                         break;
  88.                     }
  89.                 }
  90.  
  91.                 if(Position != -1)
  92.                     Work -> BufferPos = Position;
  93.                 else
  94.                     Work -> BufferPos = Work -> NumChars;
  95.  
  96.                 Work -> EditOp = EO_MOVECURSOR;
  97.             }
  98.         }
  99.  
  100.         if(Work -> IEvent -> ie_Code == CURSORLEFT && (Work -> IEvent -> ie_Qualifier & QUALIFIER_CONTROL))
  101.         {
  102.             if(Work -> BufferPos)
  103.             {
  104.                 WORD i,Position = -1;
  105.  
  106.                 for(i = Work -> BufferPos ; i >= 0 ; i--)
  107.                 {
  108.                     if(Work -> WorkBuffer[i] != ' ')
  109.                     {
  110.                         Position = i;
  111.  
  112.                         break;
  113.                     }
  114.                 }
  115.  
  116.                 if(Position == -1)
  117.                     Position = 0;
  118.  
  119.                 if(Position)
  120.                 {
  121.                     i = Position;
  122.  
  123.                     Position = -1;
  124.  
  125.                     for( ; i >= 0 ; i--)
  126.                     {
  127.                         if(Work -> WorkBuffer[i] == ' ')
  128.                         {
  129.                             Position = i + 1;
  130.  
  131.                             break;
  132.                         }
  133.                     }
  134.                 }
  135.  
  136.                 if(Position != -1)
  137.                     Work -> BufferPos = Position;
  138.                 else
  139.                     Work -> BufferPos = 0;
  140.  
  141.                 Work -> EditOp = EO_MOVECURSOR;
  142.             }
  143.         }
  144.  
  145.         if(Work -> Actions & SGA_END)
  146.             LTP_AddHistory(Work);
  147.     }
  148.     else
  149.     {
  150.         if(*Msg != SGH_CLICK)
  151.             return(FALSE);
  152.     }
  153.  
  154.     return(TRUE);
  155. }
  156.